locals {
  rds_mysql_groups = {
    myapp = {
      name       = "rds-myapp-dev"
      flavor     = "rds.mysql.n1.large.2.ha"
      rc_mode    = "async"
      ava_zone   = ["${var.REGION}a", "${var.REGION}c"]
      vpc_id     = data.terraform_remote_state.vpc.outputs.vpc_info.id
      subnet_id  = data.terraform_remote_state.subnet.outputs.subnet_info["subnet-me212-dev-baidu_hub-db-mysql"].id
      vsg_id     = data.terraform_remote_state.vsg.outputs.vsg_info.vsg_mysql.vsg_id
      db_type    = "MySQL"
      db_version = "8.0"
      db_pwd     = var.pwd_rds_myapp
      disk_size  = 100
    }
    miniapp = {
      name       = "rds-miniapp-dev"
      flavor     = "rds.mysql.n1.large.2.ha"
      rc_mode    = "async"
      ava_zone   = ["${var.REGION}a", "${var.REGION}c"]
      vpc_id     = data.terraform_remote_state.vpc.outputs.vpc_info.id
      subnet_id  = data.terraform_remote_state.subnet.outputs.subnet_info["subnet-me212-dev-baidu_hub-db-mysql"].id
      vsg_id     = data.terraform_remote_state.vsg.outputs.vsg_info.vsg_mysql.vsg_id
      db_type    = "MySQL"
      db_version = "8.0"
      db_pwd     = var.pwd_rds_miniapp
      disk_size  = 100
    }
  }
}

module "rds" {
  source = "../../../modules/rds"

  for_each = local.rds_mysql_groups

  rds_name            = each.value.name
  rds_flavor          = each.value.flavor
  ha_replication_mode = each.value.rc_mode
  vpc_id              = each.value.vpc_id
  subnet_id           = each.value.subnet_id
  vsg_id              = each.value.vsg_id
  availability_zone   = each.value.ava_zone
  db_type             = each.value.db_type
  db_version          = each.value.db_version
  db_pwd              = each.value.db_pwd
  disk_size           = each.value.disk_size
}